<%--
  Created by IntelliJ IDEA.
  User: W
  Date: 2025/9/18
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String name = request.getParameter("username");
    String pwd = request.getParameter("passwd");
    String rememberMe = request.getParameter("rememberMe");
    if("admin".equals(name) && "123456".equals(pwd)){
        session.setAttribute("username", name);
        Cookie usernameCookie = new Cookie("username", name);
        Cookie passwdCookie = new Cookie("passwd", pwd);
        Cookie rememberMeCookie = new Cookie("rememberMe", rememberMe != null ? "on" : "");
        if(rememberMe != null && rememberMe.equals("on")){
            usernameCookie.setMaxAge(60 * 60 * 24 * 7);
            passwdCookie.setMaxAge(60 * 60 * 24 * 7);
            rememberMeCookie.setMaxAge(60 * 60 * 24 * 7);
        }else{
            usernameCookie.setMaxAge(0);
            passwdCookie.setMaxAge(0);
            rememberMeCookie.setMaxAge(0);
        }
        response.addCookie(usernameCookie);
        response.addCookie(passwdCookie);
        response.addCookie(rememberMeCookie);
        request.getRequestDispatcher("success.jsp").forward(request, response);
    }else{
        session.setAttribute("error", "用户名或密码错误");
        request.getRequestDispatcher("error.jsp").forward(request, response);
    }
%>

<html>
<head>
    <title>Title</title>
</head>
<body>

</body>
</html>
